package gui;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class ZariPanel extends JPanel implements ActionListener{
    private JLabel roundLabel;
    private ZariButton zari1,zari2,zari3,zari4,zari5;
    private JButton hidhZarat;
    private int roundi=1;
    private int noHedhjeve=0;

    public ZariPanel(){
        super();
        GridBagConstraints g= new GridBagConstraints();
        setLayout(new GridBagLayout());

        roundLabel =new JLabel("Roundi: "+roundi);
        g.gridx=0;
        g.gridy=0;
        g.fill=GridBagConstraints.HORIZONTAL;
        g.insets=new Insets(10,20,10,20);
        add(roundLabel,g);


        zari1=new ZariButton();
        g.gridy=1;
        g.fill=GridBagConstraints.NONE;
        add(zari1,g);

        zari2=new ZariButton();
        g.gridy=2;
        add(zari2,g);

        zari3=new ZariButton();
        g.gridy=3;
        add(zari3,g);

        zari4=new ZariButton();
        g.gridy=4;
        add(zari4,g);

        zari5=new ZariButton();
        g.gridy=5;
        add(zari5,g);

        hidhZarat=new JButton("Hidh Zarat");
        g.gridy=6;
        g.fill=GridBagConstraints.HORIZONTAL;
        add(hidhZarat,g);

        hidhZarat.addActionListener(this);

    }

    public void actionPerformed(ActionEvent e) {
        if(e.getSource()==hidhZarat){
            if (noHedhjeve<3){
                if (!zari1.isSelected()){
                    zari1.hidhZarin();
                }
                if (!zari2.isSelected()){
                    zari2.hidhZarin();
                }
                if (!zari3.isSelected()){
                    zari3.hidhZarin();
                }
                if (!zari4.isSelected()){
                    zari4.hidhZarin();
                }
                if (!zari5.isSelected()){
                    zari5.hidhZarin();
                }
                noHedhjeve++;
            }
            if (noHedhjeve>=3){
                hidhZarat.setEnabled(false);
            }

        }
    }

    public int[] getKombinimizarave(){
        int[] zarat=new int[5];
        zarat[0]=zari1.getPike();
        zarat[1]=zari2.getPike();
        zarat[2]=zari3.getPike();
        zarat[3]=zari4.getPike();
        zarat[4]=zari5.getPike();
        return zarat;
    }

    public void resetZarat(){
        zari1.setPike(0);
        zari2.setPike(0);
        zari3.setPike(0);
        zari4.setPike(0);
        zari5.setPike(0);
        zari1.setSelected(false);
        zari2.setSelected(false);
        zari3.setSelected(false);
        zari4.setSelected(false);
        zari5.setSelected(false);
        hidhZarat.setEnabled(true);
        noHedhjeve=0;
    }

    public void roundiTjeter(){
        roundi++;
        roundLabel.setText("Roundi: "+roundi);
        updateUI();
    }
    public int getRoundi(){
        return roundi;
    }

}
